<!DOCTYPE html>
<html>
	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategy.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
	<script>
		$(function () {

		    var regionId = "";
			var currentPage = 1;
            // 限制滑动无限加载数据
            var totalPage = 2;
		    // 查询被推荐的地区
			$.get('/regions/1',function (data) {
                var html = '';
			    $.each(data,function (index, value) {
                    html += '<li class="nav-item"><a data-id="'+ value.id +'" class="nav-link" id="pills-'+ value.id +'-tab" data-toggle="pill" href="#pills-'+ value.id +'">'+ value.name +'</a></li>';
                	var content = '<div class="tab-pane fade" id="pills-'+ value.id +'"></div>';
                    $('#pills-tabContent').append(content);
			    });
			   $('#pills-tab').append(html);
                $('.nav-link').click(function () {
                     regionId = $(this).data('id');
                   if(regionId){
                       //查询当季攻略推荐和全部推荐
                       $.get('/regions/' + regionId + "/strategies",function (subData) {
                           $('#pills-'+regionId).html(subData);
                           // 加载地区时,第一页已经加载完毕
                           currentPage = 2;
                       },"html");
				   }
                });

            });

			// 攻略推荐
            $.get('/travels/commends',{type:2,pageSize:0},function (data) {
				$('#pills-top').renderValues(data, {
                    // 拼接id到超链接
                    setHref: function (item, value) {
                        var href = $(item).data('href') + value;
                        $(item).attr('href', href);
                    }
                });
                $('.carousel-item:first').addClass("active");
            });
            // 当季推荐
			$.get('/strategies',{state:1,pageSize:0},function (data) {
                $('.strategyCommend').renderValues(data,{
                    setHref: function (item, value) {
                        var href = $(item).data('href') + value;
                        $(item).attr('href', href);
                    }
				});

            });

            function query() {
              if(regionId){
                  var html = '';
                  $.get('/regions/' + regionId + "/strategies", {currentPage: currentPage,pageSize:6}, function (subData) {
                      $.each(subData.list,function (index, value) {
                          html += '<div class="col-6 mb">' +
                              '<a href="/strategyCatalogs.html?id='+ value.id +'">' +
                              '<img class="float-left " src="'+ value.coverUrl +'">' +
                              '<div class="classify-text">' +
                              '<span>'+ value.subTitle +'</span>' +
                              '<p>0人收藏</p>' +
                              '</div>\n' +
                              '</a>\n' +
                              '</div>'
                      });
                       currentPage += 1;
                       totalPage = subData.pages;
                       $('.classify').append(html);
                  },"json");
			  }
            }


            $(window).scroll(function () {
                // html 页面的高度
                // 设备屏幕的高度
                // 滑动的高度
                // 达到底部时翻页
                if ($(window).height() + $(document).scrollTop() + 1>= $(document).height()) {
                    // 解决底部翻页问题
                    if (currentPage <= totalPage) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '深不见底还是到底啦~',
                            autoClose: 2500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
        });
	</script>
	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input class="form-control searchBtn" placeholder="找攻略">
				</div>
			</div>
		</div>
	</div>

	<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
		<li class="nav-item">
			<a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
				<span style="font-weight: bold;">推荐</span>
			</a>
		</li>
	</ul>

	<div class="tab-content carousel slide" data-ride="carousel" id="pills-tabContent">
		<div class="tab-pane fade active show carousel-inner" id="pills-top">
			<div render-loop="list">
				<div class="carousel-item">
					<div class="border commend">
						<a data-href="/travelContent.html?id=" render-fun="setHref" render-key="list.id" >
							<img  render-src="list.coverUrl">
							<p render-html="list.title"></p>
						</a>
					</div>
				</div>
			</div>
			<hr>
			<div class="container strategyCommend">
				<h6>当季推荐</h6>
				<div class="row hot"  render-loop="list">
					<div class="col-4">
							<a data-href="/strategyCatalogs.html?id=" render-fun="setHref" render-key="list.id" >
								<img  render-src="list.coverUrl">
								<p render-html="list.title"></p>
							</a>
					</div>
				</div>
			</div>
		</div>

	</div>
	</body>

</html>